package com.binance.notification.web.service.abnormaltrade.job;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.binance.autojob.annotation.MyScheduledJob;
import com.binance.notification.web.service.abnormaltrade.IPriceBreakthroughsService;
import com.binance.notification.web.service.abnormaltrade.enums.AggregationTypeEnum;
import com.binance.notification.web.service.abnormaltrade.enums.IntervalEnum;
import com.binance.notification.web.service.abnormaltrade.log.LoggerUtils;

/**
 *
 * 异动提示窗(价格突破),需求参照 https://confluence.fdgahl.cn/pages/viewpage.action?pageId=5178283
 */
@Component
public class PriceBreakthroughsNoticeJob {
    private static final org.slf4j.Logger log = LoggerUtils.getLogger(PriceBreakthroughsNoticeJob.class);
    @Autowired
    private IPriceBreakthroughsService priceBreakthroughsService;

    @Value("${price.break.alert.enabled:false}")
    private boolean priceBreakAlertEnabled;

    /**
     * 监听今日最高事件
     */
    // @Scheduled(cron = "0 * * * * ?")
    @MyScheduledJob(cron = "0 * * * * ?", author = "wangxiao", alarmEmail = "louis.wang@binance.com",
            jobDesc = "监听今日最高事件")
    public void newHighDaily() {
        if (!priceBreakAlertEnabled) {
            log.info("'priceBreakAlertEnabled' not enabled");
            return;
        }
        try {
            log.info("PriceBreakthroughsNoticeJob.monitorNewHighDailyEnevnt start");
            priceBreakthroughsService.monitorSymbolListAndStore(IntervalEnum.ONE_HOUR, 24,
                    AggregationTypeEnum.AGGREGATION_MAX);
            log.info("PriceBreakthroughsNoticeJob.monitorNewHighDailyEnevnt end");
        } catch (Exception e) {
            log.error("PriceBreakthroughsNoticeJob.monitorNewHighDailyEnevnt Exception", e);
        }
    }

    /**
     * 监听本周新高事件
     */
    // @Scheduled(cron = "0 * * * * ?")
    @MyScheduledJob(cron = "0 * * * * ?", author = "wangxiao", alarmEmail = "louis.wang@binance.com",
            jobDesc = "监听本周新高事件")
    public void newHighWeekly() {
        if (!priceBreakAlertEnabled) {
            log.info("'priceBreakAlertEnabled' not enabled");
            return;
        }
        try {
            log.info("PriceBreakthroughsNoticeJob.monitorNewHighWeeklyEnevnt start");
            priceBreakthroughsService.monitorSymbolListAndStore(IntervalEnum.ONE_DAY, 7,
                    AggregationTypeEnum.AGGREGATION_MAX);
            log.info("PriceBreakthroughsNoticeJob.monitorNewHighWeeklyEnevnt end");
        } catch (Exception e) {
            log.error("PriceBreakthroughsNoticeJob.monitorNewHighWeeklyEnevnt Exception", e);
        }
    }

    /**
     * 监听本月新高事件
     */
    // @Scheduled(cron = "0 * * * * ?")
    @MyScheduledJob(cron = "0 * * * * ?", author = "wangxiao", alarmEmail = "louis.wang@binance.com",
            jobDesc = "监听本月新高事件")
    public void newHighMonthly() {
        if (!priceBreakAlertEnabled) {
            log.info("'priceBreakAlertEnabled' not enabled");
            return;
        }
        try {
            log.info("PriceBreakthroughsNoticeJob.monitorNewHighMonthlyEnevnt start");
            priceBreakthroughsService.monitorSymbolListAndStore(IntervalEnum.ONE_DAY, 30,
                    AggregationTypeEnum.AGGREGATION_MAX);
            log.info("PriceBreakthroughsNoticeJob.monitorNewHighMonthlyEnevnt end");
        } catch (Exception e) {
            log.error("PriceBreakthroughsNoticeJob.monitorNewHighMonthlyEnevnt Exception", e);
        }
    }


    /**
     * 监听今日新低事件
     */
    // @Scheduled(cron = "0 * * * * ?")
    @MyScheduledJob(cron = "0 * * * * ?", author = "wangxiao", alarmEmail = "louis.wang@binance.com",
            jobDesc = "监听今日新低事件")
    public void newLowDaily() {
        if (!priceBreakAlertEnabled) {
            log.info("'priceBreakAlertEnabled' not enabled");
            return;
        }
        try {
            log.info("PriceBreakthroughsNoticeJob.monitorNewLowDailyEnevnt start");
            priceBreakthroughsService.monitorSymbolListAndStore(IntervalEnum.ONE_HOUR, 24,
                    AggregationTypeEnum.AGGREGATION_MIN);
            log.info("PriceBreakthroughsNoticeJob.monitorNewLowDailyEnevnt end");
        } catch (Exception e) {
            log.error("PriceBreakthroughsNoticeJob.monitorNewLowDailyEnevnt Exception", e);
        }
    }


    /**
     * 监听本周新低事件
     */
    // @Scheduled(cron = "0 * * * * ?")
    @MyScheduledJob(cron = "0 * * * * ?", author = "wangxiao", alarmEmail = "louis.wang@binance.com",
            jobDesc = "监听本周新低事件")
    public void newLowWeekly() {
        if (!priceBreakAlertEnabled) {
            log.info("'priceBreakAlertEnabled' not enabled");
            return;
        }
        try {
            log.info("PriceBreakthroughsNoticeJob.monitorNewLowWeeklyEnevnt start");
            priceBreakthroughsService.monitorSymbolListAndStore(IntervalEnum.ONE_DAY, 7,
                    AggregationTypeEnum.AGGREGATION_MIN);
            log.info("PriceBreakthroughsNoticeJob.monitorNewLowWeeklyEnevnt end");
        } catch (Exception e) {
            log.error("PriceBreakthroughsNoticeJob.monitorNewLowWeeklyEnevnt Exception", e);
        }
    }

    /**
     * 监听本月新低事件
     */
    // @Scheduled(cron = "0 * * * * ?")
    @MyScheduledJob(cron = "0 * * * * ?", author = "wangxiao", alarmEmail = "louis.wang@binance.com",
            jobDesc = "监听本月新低事件")
    public void newLowMonthly() {
        if (!priceBreakAlertEnabled) {
            log.info("'priceBreakAlertEnabled' not enabled");
            return;
        }
        try {
            log.info("PriceBreakthroughsNoticeJob.monitorNewLowMonthlyEnevnt start");
            priceBreakthroughsService.monitorSymbolListAndStore(IntervalEnum.ONE_DAY, 30,
                    AggregationTypeEnum.AGGREGATION_MIN);
            log.info("PriceBreakthroughsNoticeJob.monitorNewLowMonthlyEnevnt end");
        } catch (Exception e) {
            log.error("PriceBreakthroughsNoticeJob.monitorNewLowMonthlyEnevnt Exception", e);
        }
    }

}
